<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery-3.3.1.min.js"></script>
    <style>
        li {
            list-style: none;
        }
        
        .calc {
            width: 500px;
            height: 300px;
            border: 1px solid yellowgreen;
        }
        
        ul {
            width: 500px;
            height: 200px;
            margin-top: 100px;
        }
        
        input {
            margin-left: 100px;
            width: 150px;
            height: 30px;
        }
        
        #btn {
            width: 60px;
            height: 40px;
            margin-left: 200px;
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div class="calc">
        <ul>
            <li>
                <label>用户名：</label>
                <input id="loginname" type="text" value="" placeholder="邮箱/用户名/已验证手机">
            </li>
            <li>
                <label>密&nbsp;&nbsp;&nbsp;码： </label>
                <input type="text" id="nloginpwd" placeholder="密码">
            </li>
            <li>
                <button id='btn'>提交</button>
            </li>
        </ul>
    </div>
    <script>
        var $$ = function() {};
        $$.prototype.$id = function(id) {
            return document.getElementById(id);
        }
        $$.prototype.ltrim = function(str) {
            return str.replace(/(^\s*)/g, '');
        }
        $$.prototype.rtrim = function(str) {
            return str.replace(/(\s*$)/g, '');
        }
        $$.prototype.trim = function(str) {
            return str.replace(/(^\s*)|(\s*$)/g, '');
        }
        $$ = new $$();
        var btn = $$.$id('btn');
        btn.onclick = function() {
            var userName = $$.$id('loginname').value
            console.log('用户名：' + userName + "含有空格")
            var data = $$.trim(userName)
            console.log('用户名：' + data + "去除空格")

        }
    </script>
</body>

</html>